#include <iostream>

using namespace std;

/*
 * 结构体作为参数向函数中传递
 *      值传递
 *      地址传递
 */

struct Student{
    string name;
    int age;
};

void printFunc1(struct Student s) {
    s.name = "func1";
    cout << "func1.name= " << s.name << ", func1.age= " << s.age << endl;
}

void printFunc2(struct Student * s) {
    s->name = "func2";
    cout << "func2.name= " << s->name << ", func2.age= " << s->age << endl;
}

// 加const修饰，防止修改结构体变量,常量指针   指向可以修改，但是指向的值不能修改
void printFunc3(const Student * s) {
//    s->name = "1";
}

int main() {

    Student s = {"main", 1};
    cout << "main.name= " << s.name << ", main.age= " << s.age << endl;
    printFunc1(s);
    cout << "main1.name= " << s.name << ", main1.age= " << s.age << endl;
    printFunc2(&s);
    cout << "main2.name= " << s.name << ", main2.age= " << s.age << endl;

    return 0;
}
